package concurrency;

import java.util.concurrent.ThreadFactory;

/**
 * 通过编写定制的ThreadFactory可以定制由Executor创建的线程的属性（后台、优先级、名称）
 *
 * 2018年 09月 23日 星期日
 * @author fireway
 */
public class DaemonThreadFactory implements ThreadFactory {
    private static final boolean DEBUG = true;

    @Override
    public Thread newThread(Runnable r) {
        if (DEBUG) {
            System.out.println("DaemonThreadFactory.newThread() r[" + System.identityHashCode(r) + "]");
        }

        Thread t = new Thread();

        if (DEBUG) {
            System.out.println("DaemonThreadFactory.newThread() t[" + System.identityHashCode(t) + "]");
        }

        t.setDaemon(true);

        return t;
    }
}
